home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / MOUSECOM.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  7KB  |  282 lines

  1. #include "pt.h"
  2. #include "malloc.h"
  3. #include "string.h"
  4.  
  5. void pascal
  6. /* XTAG:mouseCommand */
  7. mouseCommand(which, w, cp, menuRow, menuCol, evhead)
  8.     struct window *w;
  9.     long cp;
  10.     int which, menuRow, menuCol, evhead;
  11. {
  12.     extern unsigned char msgBuffer[];
  13.     extern struct window *selWindow;
  14.     extern long selBegin, selEnd;
  15.     extern struct window *pendWindow;
  16.     extern int searchMode;
  17.     extern int mouseVec1[];
  18.     extern int mouseVec2[];
  19.     extern int quad67, quad45, quad22;
  20.     extern int descrFileId;
  21.     extern struct event events[];
  22.     extern int helpMode;
  23.     extern unsigned char selColor;
  24.     extern unsigned char *screenChars;
  25.     extern unsigned char *userMessages[];
  26.     extern int scrRows, scrCols;
  27.     extern struct SREGS segRegs;
  28.     extern int debug;
  29.  
  30.     int deltaRow, deltaCol;
  31.     int row1, col1, row2, col2;
  32.     int i, fn, zz;
  33.     int initalButtons, cancelled;
  34.     int *vector;
  35.     unsigned char *p1, *p2, *p3;
  36.     unsigned char far *sBuffer;
  37.     unsigned char *sOffset;
  38.     unsigned int sizeOfBuffer;
  39.  
  40.     /* check for error cases */
  41.     if( w == NULL || selWindow == NULL )
  42.         return;
  43.     
  44.     /* see which vector to use */
  45.     if( which == FMOUSECOM1 )
  46.         vector = &mouseVec1[0];
  47.     else
  48.         vector = &mouseVec2[0];
  49.  
  50.     /* find the limit of the markers */
  51.     row1 = menuRow - 1;
  52.     row2 = menuRow + 1;
  53.     col1 = menuCol - 1;
  54.     col2 = menuCol + 1;
  55.     zz = 0;        /* indicates which direction */
  56.     p1 = screenChars + (scrCols<<1)*(row1) + ((col1)<<1);
  57.     p2 = p1 + (scrCols<<1);
  58.     p3 = p2 + (scrCols<<1);
  59.  
  60.     /* save the present screen characters */
  61.     /* allocate some memory to hold the screen image */
  62.     sizeOfBuffer = (unsigned)((scrCols<<1)*(row2-row1+1));
  63.     sBuffer = _fmalloc(sizeOfBuffer);
  64.     if( sBuffer == 0L ) {
  65.         msg(userMessages[NOSPACEMSG], 3);
  66.         return;    /* getBox cancelled */
  67.     }
  68.     sOffset = screenChars+(scrCols<<1)*row1;
  69.     movedata(segRegs.ds, (unsigned int)sOffset, FP_SEG(sBuffer),
  70.         FP_OFF(sBuffer), sizeOfBuffer);
  71.  
  72.     /*memcpy(screenBuffer, screenChars+(scrCols<<1)*row1,
  73.         (unsigned)((scrCols<<1)*(row2-row1+1)));*/
  74.  
  75.     /* the first time we will use the original mouse event */
  76.     initalButtons = events[evhead].buttons;
  77.     cancelled = 0;
  78.     goto firstTime;
  79.  
  80. /* this loop follows the mouse cursor and ends when the button */
  81. /* is up.  While following the mouse it displays the command */
  82. /* that would be executed if the button came up at that point */
  83. while( 1) {
  84.     /* wait for the mouse to move or the buttons to change */
  85.     while( !isMouseEvent(0) )
  86.         ;
  87.     evhead = getMouseEvent();
  88. firstTime:
  89.     deltaRow = events[evhead].vertical>>3;
  90.     deltaCol = events[evhead].horizontal>>3;
  91.  
  92.     /* now figure out which way we moved */
  93.     deltaRow = menuRow - deltaRow;
  94.     deltaCol -= menuCol;
  95.     if( deltaCol == 0 ) {
  96.         if( deltaRow == 0 ) {
  97.             zz = 0;
  98.         } else if( deltaRow > 0 ) {
  99.             zz = 1;
  100.         } else {
  101.             zz = 5;
  102.         }
  103.     } else {
  104.         fn = (100 * deltaRow) / deltaCol;
  105.         if( fn > quad67 ) {
  106.             zz = deltaRow > 0 ? 1 : 5;
  107.         } else if( fn > quad45 ) {
  108.             zz = deltaRow > 0 ? 2 : 6;
  109.             if( vector[zz] == FDONOTHING )
  110.                 zz = deltaRow > 0 ? 1 : 5;
  111.         } else if( fn > quad22 ) {
  112.             zz = deltaRow > 0 ? 2 : 6;
  113.             if( vector[zz] == FDONOTHING )
  114.                 zz = deltaRow > 0 ? 3 : 7;
  115.         } else if( fn > -quad22 ) {
  116.             zz = deltaCol > 0 ? 3 : 7;
  117.         } else if( fn > -quad45 ) {
  118.             zz = deltaRow > 0 ? 8 : 4;
  119.             if( vector[zz] == FDONOTHING )
  120.                 zz = deltaRow > 0 ? 7 : 3;
  121.         } else if( fn > -quad67 ) {
  122.             zz = deltaRow > 0 ? 8 : 4;
  123.             if( vector[zz] == FDONOTHING )
  124.                 zz = deltaRow > 0 ? 1 : 5;
  125.         } else {
  126.             zz = deltaRow > 0 ? 1 : 5;
  127.         }
  128.     }
  129.     fn = vector[zz];
  130.  
  131.     if( events[evhead].buttons == 0 )
  132.         break;
  133.     if( events[evhead].buttons != initalButtons )
  134.         cancelled = 1;
  135.     if( cancelled )
  136.         fn = 31;
  137.  
  138.     /* set up the map and draw the menu */
  139.     movedata(FP_SEG(sBuffer), FP_OFF(sBuffer), segRegs.ds,
  140.         (unsigned int)sOffset, sizeOfBuffer);
  141.     /*memcpy(screenChars+(scrCols<<1)*row1, screenBuffer,
  142.         (scrCols<<1)*(row2-row1+1));*/
  143.  
  144.     if( fn == 31 ) {
  145.     } else switch( zz ) {
  146.         case 0:
  147.             *(p2+2) = 7;
  148.             *(p2+3) = (unsigned char)(w->selColor);
  149.             break;
  150.         case 1:
  151.             *(p2+2) = 7;
  152.             *(p2+3) = (unsigned char)(w->selColor);
  153.             *(p1+2) = 30;
  154.             *(p1+3) = (unsigned char)(w->selColor);
  155.             break;
  156.         case 2:
  157.             *(p2+2) = 7;
  158.             *(p2+3) = (unsigned char)(w->selColor);
  159.             *(p1+4) = (char)187;
  160.             *(p1+5) = (unsigned char)(w->selColor);
  161.             break;
  162.         case 3:
  163.             *(p2+2) = 7;
  164.             *(p2+3) = (unsigned char)(w->selColor);
  165.             *(p2+4) = 16;
  166.             *(p2+5) = (unsigned char)(w->selColor);
  167.             break;
  168.         case 4:
  169.             *(p2+2) = 7;
  170.             *(p2+3) = (unsigned char)(w->selColor);
  171.             *(p3+4) = (char)188;
  172.             *(p3+5) = (unsigned char)(w->selColor);
  173.             break;
  174.         case 5:
  175.             *(p2+2) = 7;
  176.             *(p2+3) = (unsigned char)(w->selColor);
  177.             *(p3+2) = 31;
  178.             *(p3+3) = (unsigned char)(w->selColor);
  179.             break;
  180.         case 6:
  181.             *(p2+2) = 7;
  182.             *(p2+3) = (unsigned char)(w->selColor);
  183.             *(p3) = (char)200;
  184.             *(p3+1) = (unsigned char)(w->selColor);
  185.             break;
  186.         case 7:
  187.             *(p2+2) = 7;
  188.             *(p2+3) = (unsigned char)(w->selColor);
  189.             *(p2) = 17;
  190.             *(p2+1) = (unsigned char)(w->selColor);
  191.             break;
  192.         case 8:
  193.             *(p2+2) = 7;
  194.             *(p2+3) = (unsigned char)(w->selColor);
  195.             *(p1) = (char)201;
  196.             *(p1+1) = (unsigned char)(w->selColor);
  197.             break;
  198.     }
  199.     updateScreen(row1, row2);
  200.     if( helpMode > 0 ) {
  201.         readLine(descrFileId, 80L*(long)(fn), &msgBuffer[0], 0);
  202.         msgBuffer[78] = '\0';
  203.         msg(msgBuffer, 1);
  204.     }
  205. }
  206.  
  207. if( !cancelled ) {
  208.     /* find the indicated command */
  209.     switch( fn ) {
  210.     case FCOPYTO:    /* copy selection to this point */
  211.         zz = COPY;
  212.         goto moveAndCopy;
  213.  
  214.     case FMOVETO:    /* move selection to this point */
  215.         zz = MOVE;
  216.     moveAndCopy:
  217.         /* find out what window (if any) and where the mouse was */
  218.         xyToPos(&menuRow, &menuCol, &i, &cp, &w);
  219.         /* adjust to the selection mode */
  220.         cp = adjustSelMode(w->fileId, cp);
  221.         copyMove(selWindow, selBegin, selEnd, w, cp, zz);
  222.         break;
  223.  
  224.     default:
  225.         command(fn, 0, w);
  226.     }
  227. }
  228. _ffree(sBuffer);
  229. redrawBox(row1, col1, row2, col2);
  230. if( helpMode > 0 )
  231.     msg("", 1);
  232. }
  233.  
  234. long pascal
  235. /* XTAG:adjustSelMode */
  236. adjustSelMode(fid, cp)
  237.     int fid;
  238.     long cp;
  239. {
  240.     extern unsigned char msgBuffer[];
  241.     extern int selMode;
  242.     
  243.     unsigned char ch;
  244.  
  245.     /* get the first character so we can handle the special cases */
  246.     ch = readChar(fid, cp);
  247.  
  248.     switch( selMode ) {
  249.     case SELLINE:
  250.         if( ch == '\n' )
  251.             --cp;
  252.         while( 1 ) {
  253.             ch = readChar(fid, cp);
  254.             if( ch == '\n' || ch == '\0' )
  255.                 break;
  256.             --cp;
  257.         }
  258.         ++cp;
  259.         break;
  260.     case SELWORD:
  261.         /* only search if cp is inside a word */
  262.         if( isalnum(ch) || ch == '_' ) {
  263.             while( 1 ) {
  264.                 ch = readChar(fid, cp);
  265.                 if( !isalnum(ch) && ch != '_' )
  266.                     break;
  267.                 --cp;
  268.             }
  269.             ++cp;
  270.         }
  271.         break;
  272.     default:
  273.         /* no adjustment for character mode */
  274.         break;
  275.     }
  276.     if( readChar(fid, cp) == '\n' ) {
  277.         if( readChar(fid, --cp) != '\r' )
  278.             ++cp;
  279.     }
  280.     return cp;
  281. }
  282.